"""
在 CPU 密集型任务中
"""
import threading
import time
import os
from multiprocessing import Process, cpu_count
# from threading import Thread

class MuchCPU(threading.Thread):
    def run(self) -> None:
        print(f'OS PID {os.getpid()}')
        s = sum(2 * i + 1 for i in range(100_000_000))


if __name__ == '__main__':
    worker = [MuchCPU() for f in range(cpu_count())]
    t = time.perf_counter()
    for p in worker:
        p.start()
    for p in worker:
        p.join()
    print(f'work took {time.perf_counter() - t:.3f} seconds')
